home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT9 / FINDF.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-29  |  4.1 KB  |  94 lines

  1. ;
  2. ;       Program FindF ( Chapter 9 )
  3. ;
  4. page 55,132
  5. .model  small
  6. .stack
  7. .data
  8. DTA     db      21 dup (?)              ; first 21 byte reserved 
  9. Attrib  db      ?               ;======== File Attributes:
  10.                     ; 01 -  Read Only  
  11.                     ; 02 -  Hidden
  12.                     ; 04 -  System
  13.                     ; 08 -  Volume Id
  14.                     ; 10 -  Directory
  15.                     ; 20 -  Archive
  16. Time    dw      ?                       ; time of last modification
  17. Date    dw      ?                       ; date of last modification
  18. Fsize   dd      ?                       ; size of file in bytes
  19. NameF   db      13 dup (' ')            ; name of file
  20.     db      85 dup (?)              ; not used but defined (up to 128 bytes)
  21. FName   db      80 dup(0)               ; file name mask (ASCIZ string)
  22.  
  23. flags   dw      0
  24.  
  25. .code
  26. .startup
  27. ;===    Accepting parameters (file mask)
  28.     pushf
  29.     pushf
  30.     pop     ax
  31.     and     ax,not 0200h
  32.     or      ax,0100h
  33.     push    ax
  34.     popf
  35.     pop     flags
  36.     sti
  37.     
  38.     
  39.     
  40.     mov     ah,51h                  ; function 51h - get PSP segment
  41.     int     21h                     ; DOS service call
  42.     mov     es,bx                   ; ES points to PSP
  43.     mov     bx,0                    ; BX will be used as index
  44.     mov     cl,es:[80h]             ; length of parameter string into CX
  45.     mov     ch,0                    ; high part of parameter length = 0
  46.     cmp     cl,3                    ; parameter must be longer than 3 chars 
  47.     jb      ExProg                  ; if parameter shorter, exit
  48. GetParm:mov     al,es:[bx+82h]          ; get current character of parameter
  49.     cmp     al,0Dh                  ; Line Feed?
  50.     jne     TestCR                  ; if not - check for CR
  51.     mov     al,0                    ; replace Line Feed with 0 (ASCIIZ)
  52.     jmp     CopChar                 ; add current character to string
  53. TestCR: cmp     al,0Ah                  ; Carriage return?
  54.     jne     CopChar                 ; if not, add current character 
  55.     mov     al,0                    ; replace Carriage Return with 0 
  56. CopChar:mov     FName[bx],al            ; and copy it into data segment
  57.     inc     bx                      ; increase characters counter
  58.     loop    GetParm                 ; get next character
  59. ;===    Set DTA for subsecuent usage as a disk buffer
  60.     lea     dx,DTA                  ; DS:DX contain address of DTA buffer
  61.     mov     ah,1Ah                  ; function 1Ah - set DTA
  62.     int     21h                     ; DOS service call
  63. ;===    Find first matching file
  64.     lea     dx,FName                ; file name mask
  65.     mov     cx,3Fh                  ; file attribute mask 3Fh - any file
  66.     mov     ah,4Eh                  ; function 4Eh - Find First
  67.     int     21h                     ; DOS service call
  68. ;===    If search failed, exit from the program 
  69. Next:   jc      ExProg                  ; file not found - exit
  70. ;===    Output file name onto the screen
  71.     mov     byte ptr NameF[12],0Dh  ; add LF symbol to file name
  72.     mov     byte ptr NameF[13],0Ah  ; add CR symbol to file name
  73.     mov     byte ptr NameF[14],'$'  ; add EndOfString symbol to file name
  74.     mov     dx,offset NameF         ; address of file name for outputting
  75.     mov     ah,09                   ; function 09 - output string
  76.     int     21h                     ; DOS service call
  77. ;---    clear the string containing the file name (preparing next step) 
  78.     push    cx                      ; save CX content (file mask)
  79.     mov     cx,12                   ; set cycle counter to file name length
  80.     mov     bx,0                    ; prepare index
  81. Clear:  mov     NameF[bx],' '           ; clear next character
  82.     inc     bx                      ; increase index (go to next character)
  83.     loop    Clear                   ; perform cycle
  84. ;===    Find next matching file 
  85.     pop     cx                      ; restore file mask for DOS service (CX)
  86.     mov     ah,4Fh                  ; function 4Fh - Find First
  87.     int     21h                     ; DOS service call
  88. ;===    Jump to checking whether the searching was successful   
  89.     jmp     Next                    ; process next file
  90. ;===    Final block: leave the program with the return code 0   
  91. ExProg: mov     ax,4C00h                ; function 4Ch - terminate process
  92.     int     21h                     ; DOS service call
  93.     end
  94.